package cn.itcast.spring3.demo1;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

public class AccountServiceImpl implements AccountService {
	private AccountDao accountDao;
	private TransactionTemplate template;
	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	public void setTemplate(TransactionTemplate template) {
		this.template = template;
	}

	public AccountServiceImpl() {
		
	}

	public void transfer(final String from, final String to, final Double money) {
		template.execute(new TransactionCallbackWithoutResult() {
			
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus arg0) {
				
				accountDao.out(from, money);
				int d=1/0;
				accountDao.in(to, money);
				
			}
		});
	}

}
